<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue监测数据改变的原理</title>
    <script src="../js/vue-2.6.12开发.js"></script>
</head>

<body>

    <div id="root">
        <h1>学校信息</h1>

        <h2>学校名称:{{school.name}}</h2>
        <h2>学校地址:{{school.address}}</h2>
        <h2>校长:{{school.leader}}</h2>
        <br>
        <h1>学生信息</h1>
        <button @click="addSex">点我添加学生性别</button>
        <h2>姓名{{student.name}}</h2>
        <h2 v-if="student.sex">性别:{{student.sex}}</h2>
        <h2>年龄:真实:{{student.age.rAge}},对外:{{student.age.sAge}}</h2>
        <br>

        <ul>
            <li v-for="(f,index) in student.frinends" :key="index">{{f.name}}-{{f.age}}</li>
        </ul>
    </div>
    <script>
        const vm = new Vue({
            el: '#root',
            data: {
                school: {
                    name: 'B站',
                    address: 'bbbbbb',
                },
                student: {
                    name: 'tom',
                    age: {
                        rAge: 30,
                        sAge: 40
                    },
                    frinends: [{
                        name: 'jerry',
                        age: 35
                    }, {
                        name: 'tome', age: 36
                    }
                    ]
                }
            },
            methods: {
                addSex() {
                    // Vue.set(this.student, 'sex', '男')
                    this.$set(this.student, 'sex', '女')
                }
            }
        })
    </script>
</body>

</html>